<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <base href="http://localhost:8080/bookstore/">
    <script src="static/script/jquery-1.7.2.js"></script>
    <link rel="stylesheet" href="static/style/style.css">
    <script src="static/script/vue.js"></script>
    <script src="static/script/axios-0.18.0.js"></script>
    <link rel="stylesheet" href="element-ui-2.13.0/lib/theme-chalk/index.css">
    <script src="element-ui-2.13.0/lib/index.js"></script>
</head>
<body>
<div id="register-container">
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="用户名" prop="pass">
            <el-input type="text" v-model="ruleForm.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="checkPass">
            <el-input type="password" v-model="ruleForm.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="checkPass">
            <el-input type="password" v-model="ruleForm.password1" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="age">
            <el-input v-model.number="ruleForm.email" type="email"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">注册</el-button>
        </el-form-item>
    </el-form>
</div>
<script>
    new Vue({
        el:"#register-container",
        data(){
            return{
                ruleForm:{
                    username:"",
                    password:"",
                    password1:"",
                    email:""
                }
            }
        },methods:{
            submitForm(val){
                if(this.ruleForm.password==this.submitForm.password1){
                    alert("两次密码不相同");
                }else {
                    var user={
                        username:this.ruleForm.username,
                        password:this.ruleForm.password,
                        email:this.ruleForm.email
                    }
                    if(user.username!=''&&user.password!=''&&user.email!=''){
                        var jsonUser = JSON.stringify(user);
                        console.log(jsonUser)
                        var params = new URLSearchParams();
                        params.append("user",jsonUser);
                        axios.post("UserServlet?action=register",params).then(response=>{
                            if(response.status===202){
                                location.href="pages/user/login.html";
                            }
                        },error=>{

                        })
                    }
                }
            }
        }
    });
</script>
<script>
    $(function () {
       $("input").onblur(function () {
           if(this.val()==''){
               this.css("border-color","red");
           }
       })
    });
</script>
</body>
</html>